package io.sage.modules.outwarehouse.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.sage.annotation.Login;
import io.sage.annotation.LoginUser;
import io.sage.common.utils.R;
import io.sage.modules.employer.entity.Employer;
import io.sage.modules.outwarehouse.entity.BGoodsReceiveRecord;
import io.sage.modules.outwarehouse.service.BGoodsReceiveRecordService;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 
 *
 * @author xujh
 * @email jhang_mail@163.com
 * @date 2019-07-09 13:19:37
 */
@RestController
@RequestMapping("sage/goodsReceiveRecord")
public class BGoodsReceiveRecordController {
	
	@Autowired
	private BGoodsReceiveRecordService goodsReceiveRecordService;
	
	@RequestMapping("/list")
    @ApiOperation("查询员工申请工具列表")
    @Login
    public R list(@ApiIgnore @LoginUser Employer employer , @RequestBody JSONObject jsonObject){
    	
		Integer pageSize = jsonObject.getInteger("pageSize");
    	Integer pageNum = jsonObject.getInteger("pageNum");
    	//工具的名称
    	String goodsName = jsonObject.getString("goodsName");
    	//工具的型号
    	String goodsModel = jsonObject.getString("goodsModel");
    	//员工id
    	Integer employeeId = employer.getId();
    	if(pageSize == null || pageNum == null){
    		return R.error("参数不能为空");
    	}
    	
    	HashMap<String, Object> paramMap = new HashMap<>();
    	if(!StringUtils.isEmpty(goodsName)){
    		paramMap.put("goodsName", goodsName);
    	}
    	if(!StringUtils.isEmpty(goodsModel)){
    		paramMap.put("goodsModel", goodsModel);
    	}
    	paramMap.put("employeeId", employeeId);
    	/*paramMap.put("pageNum", pageNum);
    	paramMap.put("pageSize", pageSize);*/

 		PageHelper.startPage(pageNum, pageSize);// 设置分页的起始码以及页面大小
 		List<BGoodsReceiveRecord> selectReceiveRecordList = goodsReceiveRecordService.selectReceiveRecordList(paramMap);
 		
 		PageInfo<BGoodsReceiveRecord> goodsReceiveRecordList = new PageInfo<BGoodsReceiveRecord>(selectReceiveRecordList);// 传入list就可以了

 		return R.ok().put("goodsReceiveRecordList", goodsReceiveRecordList);
    }

}
